<?php

namespace app\common\model;

use think\Model;

class ClassDay extends Model
{
    // 表名
    protected $name = 'class_day';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = false;
    protected $append = ['start_time_text', 'end_time_text'];

    public function details()
    {
        return $this->hasMany('ClassDayDetail', 'class_day_id');
    }

    public function getStartTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['start_time'];
        return date('H:i', strtotime($value));
    }

    public function getEndTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['end_time'];
        return date('H:i', strtotime($value));
    }

}
